package com.saltedfish.tool.dialog;

import android.app.Activity;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;

import com.saltedfish.tool.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import cn.droidlover.xdroidmvp.popwindow.DialogHelper;
import cn.droidlover.xdroidmvp.view.picker.WheelDateView;

public class UIMonthDialog extends DialogHelper {

    @BindView(R.id.tvBack)
    ImageView tvBack;

    @BindView(R.id.whellViewYear)
    WheelDateView whellViewYear;

    @BindView(R.id.whellViewYearText)
    WheelDateView whellViewYearText;

    @BindView(R.id.whellViewMonth)
    WheelDateView whellViewMonth;

    @BindView(R.id.whellViewMonthText)
    WheelDateView whellViewMonthText;

    private String month;

    private String year1;

    private String month1;

    public UIMonthDialog(Activity context) {
        super(context, R.style.AlertDialogStyle);
        this.mContext = context;

        setFullWidthScreen();
        setGravity(Gravity.BOTTOM);
        setAnimSet(R.style.popRightPopAnim);

    }


    public void updateDate(String months) {
        this.month = months;
        String[] monthList = months.split("年");
        whellViewYear.setSelectedItem(monthList[0]);
        String[] monthlist2 = monthList[1].split("月");
        whellViewMonth.setSelectedItem(monthlist2[0]);
    }


    @Override
    protected int getLayoutId() {
        return R.layout.dialog_ui_month;
    }

    private List<String> yearList;
    private List<String> monthList;
    private List<String> yearTextList;
    private List<String> monthTextList;
    @Override
    protected void initView() {
        yearList = new ArrayList<>();
        monthList = new ArrayList<>();
        yearTextList = new ArrayList<>();
        monthTextList = new ArrayList<>();

        yearTextList.add("年");
        monthTextList.add("月");

        for (int i = 2022; i <= 2026; i++) {
            yearList.add(String.valueOf(i));
        }

        for (int i = 1; i <= 12; i++) {
            String index;
            if(i<10){
                index ="0" + i;
            }else{
                index = i +"";
            }
            monthList.add(index);
        }

        tvBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });

        whellViewYearText.setTextColor(0XFF333333);
        whellViewMonthText.setTextColor(0XFF333333);

        whellViewYear.setItemsFour(yearList);
        whellViewMonth.setItemsTwo(monthList);

        whellViewYearText.setItems(yearTextList);
        whellViewMonthText.setItems(monthTextList);



        whellViewYear.setOnWheelViewListener(new WheelDateView.OnWheelViewListener() {
            @Override
            public void onSelected(boolean isUserScroll, int selectedIndex, String item) {
              //  XLog.e("-----whellViewYear----"+item);
                year1 = item;
            }
        });

        whellViewMonth.setOnWheelViewListener(new WheelDateView.OnWheelViewListener() {
            @Override
            public void onSelected(boolean isUserScroll, int selectedIndex, String item) {
             //   XLog.e("----whellViewMonth-----"+item);
                month1 = item;
            }
        });

    }


    @Override
    protected void initData() {

    }


    @Override
    protected void dialogDismiss() {
        dismiss();
    }

    @Override
    public void dismiss() {
        month = year1 +"年" + month1 +"月";
        if (listener != null) {
            listener.onClick(month);
        }
        mContext.getWindow().setStatusBarColor(mContext.getResources().getColor(R.color.color_white));
        super.dismiss();

    }

}
